import {
  GM_addValueChangeListener,
  GM_deleteValue,
  GM_getResourceText,
  GM_getResourceURL,
  GM_getValue,
  GM_listValues,
  GM_removeValueChangeListener,
  GM_setValue,
} from "tm";

let value = GM_getValue("key");
console.log(value, typeof value);

value = GM_getValue("key", 0);
console.log(value, typeof value);

GM_setValue("key", true);
value = GM_getValue("key", 0);
console.log(value, typeof value);

GM_deleteValue("key");
console.log(value, typeof value);

const list = GM_listValues();
console.log(...list);

const vclId = GM_addValueChangeListener("key", (key, oldv, newv, remote) => {
  console.log({
    [key]: {
      old: oldv,
      new: newv,
      remote: remote,
    },
  });
});
console.log(vclId, typeof vclId);

GM_setValue("key", false);
GM_removeValueChangeListener(vclId);
GM_setValue("key", "ok");

const rUrl = GM_getResourceURL("res");
console.log(rUrl, typeof rUrl);

const rText = GM_getResourceText("res");
console.log(rText, typeof rText);
